import axios from 'axios'
import api from '../api'

const API_URL = 'http://localhost:8081/api/user'

export const loginUser = async (credentials) => {
  try {
    const response = await api.post(`${API_URL}/login`, {
      userAccount: credentials.userAccount,
      userPassword: credentials.userPassword
    }, {
    })
    return response.data
  } catch (error) {
    throw new Error(error.response?.data?.message || '登录失败')
  }
}

export const getCurrentUser = async () => {
  try {
    const response = await api.get(`${API_URL}/get/login`)
    return response.data
  } catch (error) {
    throw new Error('获取用户信息失败')
  }
}
